<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.util.*,java.text.*"%>
    <%@ page import="com.bean.ywj.*" %>
    <%@ page import="shopping.*" %>
    
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	购物车商品
		<%
		Map cart = (Map) session.getAttribute("cart");
		double total = 0;
		if (cart == null || cart.size() == 0)
			out.println("<p>购物车当前为空.</p>");
		else {
			// 创建用于显示内容的变量
			Set cartItems = cart.keySet();
			Object[] isbn = cartItems.toArray();
			Title book;
			CartItem cartItem;
			int quantity;
			double price, subtotal;
	%>
		<table cellSpacing=0 cellPadding=0 width=490 border=1>
			<thead>
				<tr align="center">
					<th>书籍名称</th><th>数量</th><th>价格</th><th>小计</th>
				</tr>
			</thead>
			<%
				int i = 0;
					while (i < isbn.length) {
						// 计算总和
						cartItem = (CartItem) cart.get((String) isbn[i]);
						book = cartItem.getTitles();
						quantity = cartItem.getQuantity();
						price = book.getPrice();
						subtotal = quantity * price;
						total += subtotal;
						i++;
			%>
			<th>书籍名称</th><th>数量</th><th>价格</th><th>小计</th>
			
			<%
				}
			%>
			<tr>
				<td colspan="4" class="bold right">
					<b>总计： </b><%=new DecimalFormat("0.00").format(total)%>
				</td>
			</tr>
		</table>
		<%
			session.setAttribute("total", new Double(total));
			}
		%>
		<a href="../viewBook.jsp">继续购物</a>
		<form method="get" action="../order.jsp">
			<input type="submit" value="结 账" />
		</form>

</body>
</html>